package ve.com.wayoyo.wuml_case.DibujoDiagramas;

import java.util.ArrayList;

import ve.com.wayoyo.wuml_case.Painter;
import ve.com.wayoyo.wuml_case.UserPref;
import ve.com.wayoyo.wuml_case.Exceptions.AtributoERException;
import ve.com.wayoyo.wuml_case.Exceptions.CardinalityException;
import ve.com.wayoyo.wuml_case.Exceptions.MultiplicityException;
import ve.com.wayoyo.wuml_case.Exceptions.TipoDatoException;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Point;

public class CompClase extends Componente {

	static final int textMargin = 15;

	private Paint _borderPaint = Painter.getInstancia().getDefaultBorderPaint();
	private Path _borderPath = new Path();

	private ArrayList<CompAtributo> _atributos = new ArrayList<CompAtributo>();
	private ArrayList<CompMetodo> _metodos = new ArrayList<CompMetodo>();
	private String longestString;

	public CompClase(String Titulo) {
		if (UserPref.getInstancia().isUsingConvections() && Titulo.length() > 1) {
			this.Titulo = Titulo.substring(0, 1).toUpperCase()
					+ Titulo.substring(1);
		} else {
			this.Titulo = Titulo;
		}
		allowRecursivity = true;
		_centerPoint = new Point();
		Point punto = new Point();
		punto.x = 20;
		punto.y = 20;
		this.setAnchor(punto);
		_width = Painter.getInstancia().getTextPaint(false, 1)
				.measureText(Titulo)
				+ textMargin;
		if (_width < 30) {
			_width = 30;
		}
		longestString = Titulo;

		// Antiguo Metodo de Conexion
		_topAnchors = new BorderAnchors(4, Anchor, new Point(
				(int) (Anchor.x + _width), Anchor.y));
		_bottomAnchors = new BorderAnchors(4, new Point(Anchor.x,
				(int) (Anchor.y + _height)), new Point(
				(int) (Anchor.x + _width), (int) (Anchor.y + _height)));
		_leftAnchors = new BorderAnchors(4, Anchor, new Point((int) (Anchor.x),
				(int) (Anchor.y + _height)));
		_rightAnchors = new BorderAnchors(4, new Point(
				(int) (Anchor.x + _width), (int) (Anchor.y)), new Point(
				(int) (Anchor.x + _width), (int) (Anchor.y + _height)));

		// Nuevo Metodo de Conexion
		_connectionPoints = new Point[16];
		_connectionPointsCost = new int[16];
		float cpDistX = _width / 5;
		float cpDistY = _height / 5;
		for (int i = 0; i < 4; i++) {
			_connectionPoints[i] = new Point(
					(int) (Anchor.x + ((i + 1) * cpDistX)), Anchor.y);
		}
		for (int i = 4; i < 8; i++) {
			_connectionPoints[i] = new Point((int) (Anchor.x + _width),
					(int) (Anchor.y + ((i - 3) * cpDistY)));
		}
		for (int i = 8; i < 12; i++) {
			_connectionPoints[i] = new Point(
					(int) ((Anchor.x + _width) - ((i - 7) * cpDistX)),
					(int) (Anchor.y + _height));
		}
		for (int i = 12; i < 16; i++) {
			_connectionPoints[i] = new Point(Anchor.x,
					(int) ((Anchor.y + _height) - ((i - 11) * cpDistY)));
		}
	}

	@Override
	public void Dibujar(Canvas c, boolean isFcoused, float globalScale,
			int offSetX, int offSetY) {
		
		int posX = Anchor.x + offSetX;
		int posY = Anchor.y + offSetY;
		Paint _textPaint = Painter.getInstancia().getTextPaint(false,
				globalScale);

		_width = _textPaint.measureText(longestString) / globalScale
				+ textMargin;

		// Dibujamos el Cuadro
		_borderPath.reset();
		_borderPath.moveTo(posX * globalScale, posY * globalScale);
		_borderPath.lineTo((posX + _width) * globalScale, posY * globalScale);
		_borderPath.lineTo((posX + _width) * globalScale, (posY + _height)
				* globalScale);
		_borderPath.lineTo(posX * globalScale, (posY + _height) * globalScale);
		_borderPath.close();
		c.drawPath(_borderPath,
				Painter.getInstancia().getBorderPaint(_currentState));

		/*
		 * for (int i = 0; i < 16; i++) {
		 * c.drawCircle(_connectionPoints[i].x+offSetX,
		 * _connectionPoints[i].y+offSetY, 3, _borderPaint); }
		 * 
		 * c.drawCircle(_centerPoint.x+offSetX, _centerPoint.y+offSetY, 3,
		 * _borderPaint);
		 */

		// Dibujamos la linea del titulo
		c.drawLine(posX * globalScale, (posY + 30) * globalScale,
				(posX + _width) * globalScale, (posY + 30) * globalScale,
				_borderPaint);

		// Dibujamos el titulo
		float textSize = _textPaint.measureText(Titulo);
		float distToMid = (((_width) * globalScale) - textSize) / 2;
		c.drawText(Titulo, (posX * globalScale) + distToMid, (posY + 25)
				* globalScale, _textPaint);

		// Dibujamos los atributos
		int puntoEscritura = 0;
		for (CompAtributo value : _atributos) {
			puntoEscritura += 30;
			if (value.isStatic()) {
				_textPaint.setUnderlineText(true);
				c.drawText(value.getText(), (posX + 5) * globalScale,
						(posY + 30 + puntoEscritura) * globalScale, _textPaint);
				_textPaint.setUnderlineText(false);
			} else {
				c.drawText(value.getText(), (posX + 5) * globalScale,
						(posY + 30 + puntoEscritura) * globalScale, _textPaint);
			}
		}
		// Dibujamos la linea q separa metodos y atributos
		c.drawLine(posX * globalScale, (posY + 45 + puntoEscritura)
				* globalScale, (posX + _width) * globalScale,
				(posY + 45 + puntoEscritura) * globalScale, _borderPaint);
		puntoEscritura += 10;

		// Dibujamos los metodos
		for (CompMetodo value : _metodos) {
			puntoEscritura += 30;
			if (value.isStatic()) {
				_textPaint.setUnderlineText(true);
				c.drawText(value.getText(), (posX + 5) * globalScale,
						(posY + 30 + puntoEscritura) * globalScale, _textPaint);
				_textPaint.setUnderlineText(false);
			} else {
				c.drawText(value.getText(), (posX + 5) * globalScale,
						(posY + 30 + puntoEscritura) * globalScale, _textPaint);
			}
		}

		// Dibujamos Los conectores Padre
		for (CompConector value : _conectorsBegining) {
			value.Dibujar(c, isFcoused, globalScale, offSetX, offSetY);
		}

		_textPaint.setTextSize(25);
	}

	@Override
	public boolean CalcularVisibilidad(int offSetX, int offSetY,
			float GlobalScale) {
		boolean Visible = true;
		if ((Anchor.x + _width) <= offSetX) {
			Visible = false;
		} else if (Anchor.x <= offSetX + UserPref.getInstancia().getWinWidth()) {
			Visible = false;
		} else if (Anchor.y > offSetY + UserPref.getInstancia().getWinHeight()) {
			Visible = false;
		} else if ((Anchor.y + _height) <= offSetY) {
			Visible = false;
		}
		return Visible;
	}

	@Override
	public boolean calcularTouch(Point touch) {
		boolean respuesta = false;
		if ((touch.x <= Anchor.x + _width) && (touch.x >= Anchor.x)) {
			if ((touch.y <= Anchor.y + _height) && (touch.y >= Anchor.y)) {
				respuesta = true;
				// FactoryPopup.getPopup(VistaDiagrama.getVista(), "Clases");
			}
		}
		return respuesta;
	}

	public void addAtributo(CompAtributo nuevo) {
		_atributos.add(nuevo);
		Paint textPaint = Painter.getInstancia().getTextPaint(false, 1);
		if (_width - textMargin < textPaint.measureText(nuevo.getText())) {
			_width = textPaint.measureText(nuevo.getText()) + textMargin;
			longestString = nuevo.getText();
		}
		_height += 30;
		actualizarPuntoCentral();
		actualizarAchorsPoints();
	}

	@Override
	public void calculoLongitud() {
		Paint textPaint = Painter.getInstancia().getTextPaint(false, 1);
		_width = textPaint.measureText(Titulo) + textMargin;
		longestString = Titulo;
		_height = 80;
		if (_atributos.size() == 0) {
			_height += 15;
		} else {
			for (CompAtributo atr : _atributos) {
				if (_width - textMargin < textPaint.measureText(atr.getText())) {
					_width = textPaint.measureText(atr.getText()) + textMargin;
					longestString = atr.getText();
				}
				_height += 30;
			}
		}
		if (_metodos.size() == 0) {
			_height += 15;
		} else {
			for (CompMetodo met : _metodos) {
				if (_width - textMargin < textPaint.measureText(met.getText())) {
					_width = textPaint.measureText(met.getText()) + textMargin;
					longestString = met.getText();
				}
				_height += 30;
			}
		}
		actualizarAchorsPoints();
		actualizarPuntoCentral();
	}

	public ArrayList<CompAtributo> get_atributos() {
		return _atributos;
	}

	public void set_atributos(ArrayList<CompAtributo> _atributos) {
		this._atributos = _atributos;
	}

	public void addMetodo(CompMetodo nuevo) {
		_metodos.add(nuevo);
		Paint textPaint = Painter.getInstancia().getTextPaint(false, 1);
		if (_width - textMargin < textPaint.measureText(nuevo.getText())) {
			_width = textPaint.measureText(nuevo.getText()) + textMargin;
			longestString = nuevo.getText();
		}
		_height += 30;
		actualizarPuntoCentral();
		actualizarAchorsPoints();
	}

	public Boolean validMethod(CompMetodo nuevo) {
		String stNuevo = nuevo.getDefinition();
		Boolean flag = false;
		for (CompMetodo metodo : this._metodos) {
			if ((metodo.getDefinition().equalsIgnoreCase(stNuevo))&&(flag)) {
				return false;
			}else if((metodo.getDefinition().equalsIgnoreCase(stNuevo))&&(!flag)){
				flag = true;
			}
		}
		return true;
	}

	public Boolean validAtribNew(CompAtributo nuevo) {
		for (CompAtributo atrib : this._atributos) {
			if (atrib.getNombreVariable().equals(nuevo.getNombreVariable())) {
				return false;
			}
		}
		return true;
	}

	public Boolean validAtrib(CompAtributo nuevo) {
		Boolean flag = false;
		for (CompAtributo atrib : this._atributos) {
			if (atrib.getNombreVariable().equals(nuevo.getNombreVariable())) {
				if (!flag)
					flag = true;
				else
					return false;
			}
		}
		return true;
	}

	@Override
	public void setTitulo(String titulo) {
		Paint textPaint = Painter.getInstancia().getTextPaint(false, 1);
		if (UserPref.getInstancia().isUsingConvections()) {
			this.Titulo = titulo.substring(0, 1).toUpperCase()
					+ titulo.substring(1);
			if (_width - textMargin < textPaint.measureText(Titulo)) {
				_width = textPaint.measureText(Titulo) + textMargin;
				longestString = Titulo;

			}
		} else {
			this.Titulo = titulo;
			if (_width - 10 < textPaint.measureText(Titulo)) {
				_width = textPaint.measureText(Titulo) + 10;
				longestString = Titulo;

			}
		}
		actualizarPuntoCentral();
		actualizarAchorsPoints();
	}

	@Override
	public CompConector calcularTouchConectores(Point touch) {
		for (CompConector value : _conectorsBegining) {
			if (value.calcularTouch(touch) == true)
				return value;
		}
		return null;
	}

	@Override
	public void actualizarPuntoCentral() {
		_centerPoint.set((Anchor.x + (int) (_width / 2)),
				(Anchor.y + (int) (_height / 2)));
	}

	@Override
	public void actualizarAchorsPoints() {
		_topAnchors.actualizar(Anchor, new Point((int) (Anchor.x + _width),
				Anchor.y));
		_bottomAnchors.actualizar(new Point(Anchor.x,
				(int) (Anchor.y + _height)), new Point(
				(int) (Anchor.x + _width), (int) (Anchor.y + _height)));
		_leftAnchors.actualizar(Anchor, new Point((int) (Anchor.x),
				(int) (Anchor.y + _height)));
		_rightAnchors.actualizar(new Point((int) (Anchor.x + _width),
				(int) (Anchor.y)), new Point((int) (Anchor.x + _width),
				(int) (Anchor.y + _height)));

		float cpDistX = _width / 5;
		float cpDistY = _height / 5;
		for (int i = 0; i < 4; i++) {
			_connectionPoints[i].set((int) (Anchor.x + ((i + 1) * cpDistX)),
					Anchor.y);
		}
		for (int i = 4; i < 8; i++) {
			_connectionPoints[i].set((int) (Anchor.x + _width),
					(int) (Anchor.y + ((i - 3) * cpDistY)));
		}
		for (int i = 8; i < 12; i++) {
			_connectionPoints[i].set(
					(int) ((Anchor.x + _width) - ((i - 7) * cpDistX)),
					(int) (Anchor.y + _height));
		}
		for (int i = 12; i < 16; i++) {
			_connectionPoints[i].set((int) (Anchor.x),
					(int) ((Anchor.y + _height) - ((i - 11) * cpDistY)));
		}
		Diagrama diagramaActual = null;
		if (VistaDiagrama.getVista() != null) {
			diagramaActual = VistaDiagrama.getVista().getDiagrama();
			for (CompConector value : _conectorsEnd) {
				value.actualizarRuta(diagramaActual.getComponenteById(value
						.get_fatherId()));
			}
		}
		for (CompConector value : _conectorsBegining) {
			value.actualizarRuta(this);
		}
	}

	public ArrayList<CompMetodo> get_metodos() {
		return _metodos;
	}

	public void set_metodos(ArrayList<CompMetodo> _metodos) {
		this._metodos = _metodos;
	}

	public CompMetodo getMetodoIndex(int index) {
		return this._metodos.get(index);
	}

	@Override
	public String generarDOM() {
		String DOM = "\t<Componente Tipo=\"Clase\" Titulo=\"" + Titulo
				+ "\" ID=\"" + ID + "\" AnchorX=\"" + Anchor.x
				+ "\" AnchorY=\"" + Anchor.y + "\">\n";
		for (CompAtributo value : _atributos) {
			DOM = DOM + value.generarDOM();
		}
		for (CompMetodo value : _metodos) {
			DOM = DOM + value.generarDOM();
		}
		DOM = DOM + "\t</Componente>\n";
		return DOM;
	}

	@Override
	public String getConectorsDOM() {
		String DOM = "";
		for (CompConector value : _conectorsBegining) {
			DOM = DOM + value.generarDOM();
		}
		return DOM;
	}

	public String getCode(String Lenguaje) throws MultiplicityException {
		String code = "";
		Diagrama diagrama = VistaDiagrama.getVista().getDiagrama();
		if (diagrama instanceof DiagramaClases) {
			boolean needArrayList = false;
			ArrayList<CompAtributo> generatedComposition = new ArrayList<CompAtributo>();
			ArrayList<CompAtributo> generatedAggregation = new ArrayList<CompAtributo>();
			DiagramaClases diagramaClase = (DiagramaClases) diagrama;
			if (UserPref.getInstancia().getLanguaje().equals("C#"))
				code = "namespace " + diagramaClase.getPackageName() + "\n{\n";
			else
				code = "package " + diagramaClase.getPackageName() + ";\n\n";
			try {
				for (CompConector value : _conectorsBegining) {
					if (value.get_fatherArrowType() == CompConector._arrowType.Composicion) {
						String tituloCalse = diagramaClase.getComponenteById(
								value.get_childId()).getTitulo();
						CompAtributo nuevoAtributo = new CompAtributo("_"
								+ tituloCalse, "private");
						nuevoAtributo.setTipoDato(tituloCalse);
						if (!value.get_fatherCardenalityRight().equals("1")) {
							nuevoAtributo.setNombreVariable("_lista"
									+ tituloCalse);
							nuevoAtributo.set_haveMultiplicity(true);
							nuevoAtributo.set_leftMultiplicity(value
									.get_fatherCardenalityLeft());
							nuevoAtributo.set_rightMultiplicity(value
									.get_fatherCardenalityRight());
						}
						generatedComposition.add(nuevoAtributo);
						needArrayList = true;
					} else if (value.get_fatherArrowType() == CompConector._arrowType.Agregacion) {
						String tituloCalse = diagramaClase.getComponenteById(
								value.get_childId()).getTitulo();
						CompAtributo nuevoAtributo = new CompAtributo("_"
								+ tituloCalse, "private");
						nuevoAtributo.setTipoDato(tituloCalse);
						if (!value.get_fatherCardenalityRight().equals("1")) {
							nuevoAtributo.setNombreVariable("_lista"
									+ tituloCalse);
							nuevoAtributo.set_haveMultiplicity(true);
							nuevoAtributo.set_leftMultiplicity(value
									.get_fatherCardenalityLeft());
							nuevoAtributo.set_rightMultiplicity(value
									.get_fatherCardenalityRight());
						}
						generatedAggregation.add(nuevoAtributo);
						needArrayList = true;
					}
				}
				for (CompConector value : _conectorsEnd) {
					if (value.get_childArrowType() == CompConector._arrowType.Composicion) {
						String tituloCalse = diagramaClase.getComponenteById(
								value.get_fatherId()).getTitulo();
						CompAtributo nuevoAtributo = new CompAtributo("_"
								+ tituloCalse, "private");
						nuevoAtributo.setTipoDato(tituloCalse);
						if (!value.get_childCardenalityRight().equals("1")) {
							nuevoAtributo.setNombreVariable("_lista"
									+ tituloCalse);
							nuevoAtributo.set_haveMultiplicity(true);
							nuevoAtributo.set_leftMultiplicity(value
									.get_childCardenalityLeft());
							nuevoAtributo.set_rightMultiplicity(value
									.get_childCardenalityRight());
						}
						generatedComposition.add(nuevoAtributo);
						needArrayList = true;
					} else if (value.get_childArrowType() == CompConector._arrowType.Agregacion) {
						String tituloCalse = diagramaClase.getComponenteById(
								value.get_fatherId()).getTitulo();
						CompAtributo nuevoAtributo = new CompAtributo("_"
								+ tituloCalse, "private");
						nuevoAtributo.setTipoDato(tituloCalse);
						if (!value.get_childCardenalityRight().equals("1")) {
							nuevoAtributo.setNombreVariable("_lista"
									+ tituloCalse);
							nuevoAtributo.set_haveMultiplicity(true);
							nuevoAtributo.set_leftMultiplicity(value
									.get_childCardenalityLeft());
							nuevoAtributo.set_rightMultiplicity(value
									.get_childCardenalityRight());
						}
						generatedAggregation.add(nuevoAtributo);
						needArrayList = true;
					}
				}
			} catch (CardinalityException e) {

			} catch (TipoDatoException e) {
				// TODO: handle exception
			} catch (AtributoERException e) {
				// TODO: handle exception
			}

			if (needArrayList == false) {
				for (CompAtributo value : _atributos) {
					try {
						if (value.isMultiplicity()
								&& value.get_rightMultiplicity().equals("*"))
							needArrayList = true;
					} catch (NullPointerException e) {

					}
				}
			}
			if (needArrayList) {
				if (UserPref.getInstancia().getLanguaje().equals("C#"))
					code = code + "\n\tusing System.Collections; \n\n";
				else
					code = code + "\nimport java.util.ArrayList; \n\n";
			}
			if (UserPref.getInstancia().getLanguaje().equals("C#"))
				code = code + "\tclass " + Titulo;
			else
				code = code + "public class " + Titulo;
			ArrayList<Componente> ListaImpements = new ArrayList<Componente>();
			Componente SuperClase = null;
			for (CompConector value : _conectorsBegining) {
				if (value.get_childArrowType() == CompConector._arrowType.Herencia) {
					if (value.get_currentLineType() == CompConector.NORMAL_TYPE) {
						SuperClase = diagramaClase.getComponenteById(value
								.get_childId());
					} else if (value.get_currentLineType() == CompConector.DASHED_TYPE) {
						ListaImpements.add(diagramaClase
								.getComponenteById(value.get_childId()));
					}
				}
			}
			for (CompConector value : _conectorsEnd) {
				if (value.get_fatherArrowType() == CompConector._arrowType.Herencia) {
					if (value.get_currentLineType() == CompConector.NORMAL_TYPE) {
						SuperClase = diagramaClase.getComponenteById(value
								.get_fatherId());
					} else if (value.get_currentLineType() == CompConector.DASHED_TYPE) {
						ListaImpements.add(diagramaClase
								.getComponenteById(value.get_fatherId()));
					}
				}
			}
			if (SuperClase != null) {
				if (UserPref.getInstancia().getLanguaje().equals("C#"))
					code = code + " : " + SuperClase.getTitulo();
				else
					code = code + " extends " + SuperClase.getTitulo();
			}
			if (ListaImpements.size() > 0) {
				if (UserPref.getInstancia().getLanguaje().equals("C#")) {
					if (SuperClase != null)
						code = code + ",  ";
					else
						code = code + " : ";
				} else
					code = code + " implements ";
				for (int i = 0; i < ListaImpements.size() - 1; i++) {
					code = code + ListaImpements.get(i).getTitulo() + ", ";
				}
				code = code
						+ ListaImpements.get(ListaImpements.size() - 1)
								.getTitulo();
			}
			if (UserPref.getInstancia().getLanguaje().equals("C#"))
				code = code + "\n\t{\n\n";
			else
				code = code + "\n{\n\n";

			for (CompAtributo value : _atributos) {
				if (UserPref.getInstancia().getLanguaje().equals("C#"))
					code = code + "\t\t" + value.getCode(Lenguaje) + "\n";
				else
					code = code + "\t" + value.getCode(Lenguaje) + "\n";
			}
			for (CompAtributo value : generatedComposition) {
				if (UserPref.getInstancia().getLanguaje().equals("C#"))
					code = code + "\t\t" + value.getCode(Lenguaje) + "\n";
				else
					code = code + "\t" + value.getCode(Lenguaje) + "\n";
			}
			for (CompAtributo value : generatedAggregation) {
				if (UserPref.getInstancia().getLanguaje().equals("C#"))
					code = code + "\t\t" + value.getCode(Lenguaje) + "\n";
				else
					code = code + "\t" + value.getCode(Lenguaje) + "\n";
			}
			code = code + "\n";
			try {
				if (generatedComposition.size() > 0) {
					if (UserPref.getInstancia().getLanguaje().equals("C#"))
						code = code + "\n\t\tpublic " + Titulo + "(";
					else
						code = code + "\n\tpublic " + Titulo + "(";
					for (int i = 0; i < generatedComposition.size() - 1; i++) {
						if (generatedComposition.get(i).isMultiplicity()) {
							if (generatedComposition.get(i)
									.get_rightMultiplicity().equals("*")) {
								if (UserPref.getInstancia().getLanguaje()
										.equals("C#")) {
									code = code
											+ "ArrayList lista"
											+ generatedComposition.get(i)
													.getTipoDato() + ", ";
								} else
									code = code
											+ "ArrayList<"
											+ generatedComposition.get(i)
													.getTipoDato()
											+ "> lista"
											+ generatedComposition.get(i)
													.getTipoDato() + ", ";
							} else {
								code = code
										+ generatedComposition.get(i)
												.getTipoDato()
										+ "[] arreglo"
										+ generatedComposition.get(i)
												.getTipoDato() + ", ";
							}
						} else {
							code = code
									+ generatedComposition.get(i).getTipoDato()
									+ " "
									+ generatedComposition.get(i).getTipoDato()
									+ "Nuevo, ";
						}
					}
					if (generatedComposition.get(
							generatedComposition.size() - 1).isMultiplicity()) {
						if (generatedComposition
								.get(generatedComposition.size() - 1)
								.get_rightMultiplicity().equals("*")) {
							if (UserPref.getInstancia().getLanguaje()
									.equals("C#"))
								code = code
										+ "ArrayList lista"
										+ generatedComposition
												.get(generatedComposition
														.size() - 1)
												.getTipoDato();
							else
								code = code
										+ "ArrayList<"
										+ generatedComposition
												.get(generatedComposition
														.size() - 1)
												.getTipoDato()
										+ "> lista"
										+ generatedComposition
												.get(generatedComposition
														.size() - 1)
												.getTipoDato();
						} else {
							code = code
									+ generatedComposition.get(
											generatedComposition.size() - 1)
											.getTipoDato()
									+ "[] arreglo"
									+ generatedComposition.get(
											generatedComposition.size() - 1)
											.getTipoDato();
						}
					} else {
						code = code
								+ generatedComposition.get(
										generatedComposition.size() - 1)
										.getNombreVariable()
								+ " "
								+ generatedComposition.get(
										generatedComposition.size() - 1)
										.getNombreVariable() + "Nuevo";
					}
					if (UserPref.getInstancia().getLanguaje().equals("C#"))
						code = code
								+ "){\n\t\t\t// TODO Codigo auto-generado por WUML \n";
					else
						code = code
								+ "){\n\t\t// TODO Codigo auto-generado por WUML \n";
					for (int i = 0; i < generatedComposition.size(); i++) {
						if ((generatedComposition.get(i).isMultiplicity())) {
							if (generatedComposition.get(i)
									.get_rightMultiplicity().equals("*")) {
								if (UserPref.getInstancia().getLanguaje()
										.equals("C#"))
									code = code
											+ "\t\t\t"
											+ "this."
											+ generatedComposition.get(i)
													.getNombreVariable()
											+ " = "
											+ "lista"
											+ generatedComposition.get(i)
													.getTipoDato() + ";\n";
								else
									code = code
											+ "\t\t"
											+ "this."
											+ generatedComposition.get(i)
													.getNombreVariable()
											+ " = "
											+ "lista"
											+ generatedComposition.get(i)
													.getTipoDato() + ";\n";
							} else {
								if (UserPref.getInstancia().getLanguaje()
										.equals("C#"))
									code = code
											+ "\t\t\t"
											+ "this."
											+ generatedComposition.get(i)
													.getNombreVariable()
											+ " = "
											+ "arreglo"
											+ generatedComposition.get(i)
													.getTipoDato() + ";\n";
								else
									code = code
											+ "\t\t"
											+ "this."
											+ generatedComposition.get(i)
													.getNombreVariable()
											+ " = "
											+ "arreglo"
											+ generatedComposition.get(i)
													.getTipoDato() + ";\n";
							}
						} else {
							if (UserPref.getInstancia().getLanguaje()
									.equals("C#"))
								code = code
										+ "\t\t\t"
										+ "this."
										+ generatedComposition.get(i)
												.getNombreVariable()
										+ " = "
										+ generatedComposition.get(i)
												.getNombreVariable()
										+ "Nuevo;\n";
							else
								code = code
										+ "\t\t"
										+ "this."
										+ generatedComposition.get(i)
												.getNombreVariable()
										+ " = "
										+ generatedComposition.get(i)
												.getNombreVariable()
										+ "Nuevo;\n";
						}
					}
					if (UserPref.getInstancia().getLanguaje().equals("C#"))
						code = code + "\t\t}\n";
					else
						code = code + "\n\t}\n";
				}
			} catch (Exception e) {
				System.out.println(e.getMessage());
			}

			for (CompMetodo value : _metodos) {
				if (UserPref.getInstancia().getLanguaje().equals("C#"))
					code = code + "\t\t" + value.getCode(Lenguaje, true, false)
							+ "\n";
				else
					code = code + "\t" + value.getCode(Lenguaje, true, false)
							+ "\n";
			}

			if (UserPref.getInstancia().isOverridingMethods()) {
				for (Componente value : ListaImpements) {
					if (value instanceof CompInterface) {
						for (CompMetodo met : ((CompInterface) value)
								.get_metodos()) {
							if (UserPref.getInstancia().getLanguaje()
									.equals("C#"))
								code = code + "\t\t"
										+ met.getCode(Lenguaje, true, false);
							else
								code = code + "\t"
										+ met.getCode(Lenguaje, true, false);
						}

					}
				}
				if (SuperClase != null) {
					if (SuperClase instanceof CompAbstract) {
						for (CompMetodo met : ((CompAbstract) SuperClase)
								.get_metodos()) {
							if (met.isAbstract()) {
								if (UserPref.getInstancia().getLanguaje()
										.equals("C#")) {
									// code = code + "\t\t@Override\n";
									code = code + "\t\t"
											+ met.getCode(Lenguaje, true, true);
								} else {
									code = code + "\t"
											+ met.getCode(Lenguaje, true, true);
								}
							}
						}
					}
				}
			}

			if (UserPref.getInstancia().getLanguaje().equals("C#"))
				code = code + "\n\t}\n}";
			else
				code = code + "\n}";
		}
		return code;
	}

	public void eliminarMetodo(int metodo) {
		this.get_metodos().remove(metodo);
		calculoLongitud();
	}

	public void eliminarAtributo(int position) {
		this.get_atributos().remove(position);
		calculoLongitud();
	}

	@Override
	public String getTipo() {
		return "Clase";
	}

}
